package com.wzh.project.redis.lettcue;

import io.lettuce.core.KeyValue;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

/**
*@author : 汪振海
*@createdDate : Mar 6, 2020  2:13:09 PM
*@description : <br>server
*
*/
public class LettcueServer {
	
	//private static final Logger logger=LogManager.getLogger(LettcueServer.class);
	
	
	public void init() {
		RedisClient client = RedisClient.create("redis://172.16.5.18:6379");
		StatefulRedisConnection<String, byte[]> connection = client.connect(new Test());
		RedisCommands<String, byte[]> sync = connection.sync();
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				while(true) {
					try {
						//logger.debug("sleep");
						Thread.sleep(100);
					KeyValue<String, byte[]> brpop = sync.brpop(0,"key");
					//logger.debug("brpop");
					String result =new String(brpop.getValue());
					//logger.debug("result",result);
					System.out.println("SUCCESS   result========="+result);
					} catch (Throwable e) {
						// TODO Auto-generated catch block
						System.out.println("Fail   result========="+e.toString());
					}
				}
			}
		}).start();
	}
	
	
	public static void main(String[] args) {
		new LettcueServer().init();
	}

}
